<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="beans.UseOrder" %>
<%
    String username = (String)session.getAttribute("username");
    String role = (String)session.getAttribute("role");
    Object user = session.getAttribute("user");
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>公司用车管理系统（司机队长）- 全部订单</title>
    <style>
        /* 全局样式 */
        body {
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: #f6f6f6;
            color: #333;
        }

        /* 头部样式 */
        .header {
            background: #183a8a;
            color: #fff;
            font-size: 2rem;
            font-weight: bold;
            padding: 10px 0 10px 10px;
            letter-spacing: 2px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .header-right {
            display: flex;
            align-items: center;
            margin-right: 30px;
            font-size: 1rem;
        }
        .user-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #fff;
            color: #183a8a;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            margin-right: 10px;
        }
        .user-info {
            margin-right: 20px;
            color: #fff;
        }
        .bell-icon {
            font-size: 1.3rem;
            margin-right: 20px;
            color: #fff;
        }
        .logout {
            color: #fff;
            text-decoration: none;
            margin-left: 10px;
            font-size: 1rem;
        }

        /* 主体容器 */
        .container {
            display: flex;
            height: calc(100vh - 56px);
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 220px;
            background: #183a8a;
            display: flex;
            flex-direction: column;
            padding-top: 10px;
            box-shadow: 2px 0 8px rgba(24,58,138,0.05);
        }
        .menu-item {
            color: #fff;
            padding: 18px 0 18px 32px;
            font-size: 1.15rem;
            cursor: pointer;
            border-left: 5px solid transparent;
            transition: background 0.2s, border 0.2s;
            text-decoration: none;
            display: block;
        }
        .menu-item.active, .menu-item:hover {
            background: #2450a7;
            border-left: 5px solid #fff;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(24,58,138,0.10);
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            padding: 20px 40px;
            overflow-y: auto;
        }

        /* 搜索容器 */
        .search-container {
            margin-bottom: 30px;
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        /* 搜索表单 */
        .search-form {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
        }

        /* 搜索输入框 */
        .search-input {
            flex: 1;
            min-width: 300px;
            padding: 12px 20px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1.1rem;
            box-sizing: border-box;
        }

        /* 搜索选择框 */
        .search-select {
            padding: 12px 20px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1.1rem;
            min-width: 150px;
        }

        /* 搜索按钮 */
        .search-btn {
            padding: 12px 25px;
            background: #1da1e7;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1.1rem;
            transition: background 0.2s;
        }
        .search-btn:hover {
            background: #2176b8;
        }

        /* 申请列表 */
        .application-list {
            margin-top: 20px;
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        /* 申请项 */
        .application-item {
            padding: 20px;
            margin-bottom: 15px;
            background: #f8f9fa;
            border-radius: 6px;
            border-left: 5px solid #1da1e7;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: transform 0.2s, box-shadow 0.2s;
        }
        .application-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        }

        /* 申请信息 */
        .application-info {
            flex: 1;
            font-size: 1.1rem;
        }

        /* 查看按钮 */
        .view-btn {
            padding: 10px 20px;
            background: #1da1e7;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1rem;
            margin-left: 20px;
            transition: background 0.2s;
        }
        .view-btn:hover {
            background: #2176b8;
        }

        /* 无结果提示 */
        .no-results {
            text-align: center;
            padding: 30px;
            color: #666;
            font-size: 1.2rem;
        }

        /* 状态标签 */
        .status-badge {
            display: inline-block;
            padding: 5px 12px;
            color: white;
            border-radius: 4px;
            font-size: 0.9rem;
            margin-left: 15px;
        }
        .status-approved {
            background: #28a745;
        }
        .status-rejected {
            background: #dc3545;
        }
        .status-pending {
            background: #ffc107;
        }
        .status-completed {
            background: #17a2b8;
        }
    </style>
</head>
<body>
    <div class="header">
        <div>欢迎登录公司用车管理系统（司机队长）</div>
        <div class="header-right">
            <div class="user-icon">👤</div>
            <div class="user-info">账号：<%=username%></div>
            <div class="bell-icon">🔔</div>
            <a href="${pageContext.request.contextPath}/LogoutServlet" class="logout">退出登录</a>
        </div>
    </div>

    <div class="container">
        <div class="sidebar">
            <a class="menu-item" href="DriversServlet?action=all3">系统首页</a>
            <a class="menu-item" href="DriversServlet?action=all2">个人中心</a>
            <a class="menu-item" href="ShenqingServlet?action=all">我的待办</a>
            <a class="menu-item active" href="UseOrderServlet?action=list">我处理的</a>
            <a class="menu-item" href="VehiclesServlet?action=all">全部车辆信息</a>
            <a class="menu-item" href="DriversServlet?action=all">全部司机信息</a>
        </div>

        <div class="main-content">
            <div class="search-container">
                <form class="search-form" action="${pageContext.request.contextPath}/UseOrderServlet" method="get">
                    <input type="hidden" name="action" value="search">
                    
                    <!-- 订单号 -->
                    <input type="text" name="orderId" class="search-input"
                           placeholder="订单号" value="${param.orderId}">
                    
                    <!-- 员工ID -->
                    <input type="text" name="employeeId" class="search-input"
                           placeholder="员工ID" value="${param.employeeId}">
                    
                    <!-- 审核状态 -->
                    <select name="status" class="search-select">
                        <option value="">全部状态</option>
                        <option value="已通过" ${param.status == '已通过' ? 'selected' : ''}>已通过</option>
                        <option value="未通过" ${param.status == '未通过' ? 'selected' : ''}>未通过</option>
                        <option value="已完成" ${param.status == '已完成' ? 'selected' : ''}>已完成</option>
                    </select>
                    
                    <!-- 日期范围 -->
                    <input type="date" name="startDate" class="search-input"
                           value="${param.startDate}">
                    <span>至</span>
                    <input type="date" name="endDate" class="search-input"
                           value="${param.endDate}">
                    
                    <button type="submit" class="search-btn">搜索</button>
                    <button type="button" class="search-btn"
                            onclick="location.href='${pageContext.request.contextPath}/UseOrderServlet?action=list'">
                        重置
                    </button>
                </form>
            </div>

            <div class="application-list">
                <%
                    List<UseOrder> orders = (List<UseOrder>)request.getAttribute("orders");
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                %>

                <% if(orders == null || orders.isEmpty()) { %>
                    <div class="no-results">暂无订单记录</div>
                <% } else { 
                    for(UseOrder order : orders) { 
                        if(order != null) {
                            String reviewStatus = order.getReviewStatus() != null ? order.getReviewStatus() : "状态未知";
                            String statusClass = "";
                            if("已通过".equals(reviewStatus)) {
                                statusClass = "status-approved";
                            } else if("未通过".equals(reviewStatus)) {
                                statusClass = "status-rejected";
                            } else if("已完成".equals(reviewStatus)) {
                                statusClass = "status-completed";
                            }
                %>
                    <div class="application-item">
                        <div class="application-info">
                            <div>
                                订单号：<%=order.getOrderId()%> - 
                                申请人：<%=order.getEmployeeId()%> - 
                                申请时间：<%=order.getExpectedDepartureTime() != null ? sdf.format(order.getExpectedDepartureTime()) : "未设置"%>
                            </div>
                            <div style="margin-top: 5px;">
                                目的地：<%=order.getDestination() != null ? order.getDestination() : "未设置"%> - 
                                用车事由：<%=order.getPurpose() != null ? order.getPurpose() : "未设置"%>
                            </div>
                            <span class="status-badge <%=statusClass%>"><%=reviewStatus%></span>
                        </div>
                        <button class="view-btn" 
                                onclick="location.href='${pageContext.request.contextPath}/UseOrderServlet?action=detail&orderId=<%=order.getOrderId()%>'">
                            查看详情
                        </button>
                    </div>
                <% 
                        }
                    } 
                } 
                %>
            </div>
        </div>
    </div>
</body>
</html>